using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using UnityGameFramework.Runtime;
using LS.UnityExtensions;
using UnityEngine;

namespace LS.Digitize
{
    public abstract class Writer : IWriter, IDisposable
    {
        protected int serializationDepth = 0;

        public int Deepth
        {
            get { return serializationDepth; }
        }

        public virtual void StartWriteFile()
        {
            serializationDepth++;
        }

        public virtual void EndWriteFile()
        {
            serializationDepth--;
        }

        public virtual void StartWriteObject()
        {
            serializationDepth++;
        }

        public virtual void EndWriteObject()
        {
            serializationDepth--;
        }

        public virtual void StartWriteProperty(string name)
        {
            if (name == null)
                throw new ArgumentNullException("Key or field name cannot be NULL when saving data.");
            Log.Debug<UnityEngine.Object, int>("<b>" + name + "</b> (writing property)", null, serializationDepth);
        }

        public virtual void EndWriteProperty(string name)
        {
        }

        public virtual void StartWriteCollection()
        {
            serializationDepth++;
        }

        public virtual void EndWriteCollection()
        {
            serializationDepth--;
        }

        public abstract void StartWriteCollectionItem(int index);
        public abstract void EndWriteCollectionItem(int index);
        public abstract void StartWriteDictionary();
        public abstract void EndWriteDictionary();
        public abstract void StartWriteDictionaryKey(int index);
        public abstract void EndWriteDictionaryKey(int index);
        public abstract void StartWriteDictionaryValue(int index);
        public abstract void EndWriteDictionaryValue(int index);
        public abstract void Dispose();

        public abstract void WriteNull();
        public abstract void WritePrimitive(int value);
        public abstract void WritePrimitive(float value);
        public abstract void WritePrimitive(bool value);
        public abstract void WritePrimitive(decimal value);
        public abstract void WritePrimitive(double value);
        public abstract void WritePrimitive(long value);
        public abstract void WritePrimitive(ulong value);
        public abstract void WritePrimitive(uint value);
        public abstract void WritePrimitive(byte value);
        public abstract void WritePrimitive(sbyte value);
        public abstract void WritePrimitive(short value);
        public abstract void WritePrimitive(ushort value);
        public abstract void WritePrimitive(char value);
        public abstract void WritePrimitive(string value);
        public abstract void WritePrimitive(byte[] value);

        public Writer()
        {
        }
    }
}